<?php

if(isset($_POST['dt_inicial']) or isset($_POST['dt_final']))
{
    include_once 'app.ado/DataBase.php';
    
    $s = new DataBase();
    $db = $s->getConn();
    
    include 'app.functions/formataData.php';
    
    $dt_inicial = isset($_POST['dt_inicial']) ? formataData($_POST['dt_inicial']) : '2000-01-01';
    $dt_final   = isset($_POST['dt_final']) ? formataData($_POST['dt_final']) : date('Y-m-d');

//    $sql = 'select * from Ctrl_Chaves
//where (dt_inicial_controle between "'.$dt_inicial.'" and "'.$dt_final.'")
//or (dt_final_controle between "'.$dt_inicial.'" and "'.$dt_final.'")';
    
    $sql = 'select * from Ctrl_Chaves
where (dt_inicial_controle between ? and ?)
or (dt_final_controle between ? and ?)';
    
    $sth = $db->prepare($sql);

    $sth->execute(array($dt_inicial,$dt_final,$dt_inicial,$dt_final));

    $req = $sth->fetchAll(PDO::FETCH_CLASS, "CrlChave");

    //var_dump($req);
    
    $rel = new TRelChave($req);
    $rel->render();

    //header('location: index.php');
}

?>